﻿using IOP.ISEA;
using IOP.SgrA;
using IOP.SgrA.SilkNet.Vulkan;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace VkSample53
{
    class Program
    {
        static async Task Main(string[] args)
        {
            CreateISEA(true);
            var h = Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((config) =>
                {
                    config.SetBasePath(Directory.GetCurrentDirectory());
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) config.AddVulkanJsonFile("Vulkan.json");
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) config.AddVulkanJsonFile("Vulkan-Linux.json");
                    else throw new NotSupportedException("Not supported Platform");
                })
                .ConfigureSgrAHost((sgra) =>
                {
                    sgra.AddVulkanEnvironmental();
                    sgra.UseStartup<Startup>();
                }).ConfigureLogging((logger) => logger.AddConsole()); ;
            await h.RunConsoleAsync();
        }

        static void CreateISEA(bool isNeed)
        {
            if (!isNeed) return;
            BallData ballData = new BallData();
            ballData.GenBallData(9);
            ISEADocument document = new ISEADocument();
            MeshNode ball = document.CreateEmptyMeshNode("BallMesh", (int)ballData.VCount, MeshMode.Vertex)
                .AddMeshData(ballData.Data, 24, 0, MeshDataPurpose.COMPLEX, false);
            RenderObjectNode beltObject = new RenderObjectNode()
            {
                Comonents = new System.Collections.Generic.List<Node> { ball },
                Name = "Ball"
            };
            document.AddNode(beltObject, out _);
            document.Save(AppContext.BaseDirectory, "Test53");
        }
    }
}
